﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using static Marchers.Grpc.Amadeus;

namespace Grpc.ApiClient.Controllers
{
    [ApiController]
    [Route("api/amadeus")]
    public class AmadeusController : ControllerBase
    {
        private readonly ILogger<AmadeusController> logger;
        private readonly AmadeusClient amadeusClient;

        public AmadeusController(ILogger<AmadeusController> logger, AmadeusClient amadeusClient)
        {
            this.logger = logger;
            this.amadeusClient = amadeusClient;
        }

        [HttpGet("")]
        public Task<string> HelloWorld()
        {
            return Task.FromResult("Hello world Amadeus");
        }

        [HttpGet("grpc/{input}")]
        public async Task<string> HelloGrpc(string input)
        {
            var response = await amadeusClient.SaveAmadeusAsync(new Marchers.Grpc.SaveAmadeusRequest
            {
                Name = input
            });

            logger.LogInformation($"return value: {response.Result}");
            return response.Result;
        }
    }
}
